package casclient.controller;

import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @Author: Liudao
 * @Date: 2022-10-15-17:04
 * @Description:
 */
@Controller
public class Client2Controller {
    @GetMapping("/client2")
    @ResponseBody
    public String client2(){
        return "client2";
    }

    @GetMapping("/logout")
    public String logout(HttpSession session){

        // String loginName = CasLoginModule.LOGIN_NAME;
        Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
        if(assertion != null){
            String name = assertion.getPrincipal().getName();
            System.out.println("name = " + name);
        }
        session.invalidate();
        return "redirect:http://cas.ldg.com:8080/cas/logout?service=http://client2.cas.ldg.com:7002/client2";
    }
}
